/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.jfonia.view.symbols;

import org.jfonia.assets.fonts.Fughetta;
import org.jfonia.connect5.basics.MutableValueNode;
import org.jfonia.connect5.basics.ValueNode;
import org.jfonia.connect5.basics.Observer;
import org.jfonia.constants.SymbolConstants;

/**
 * Symbol representing an accidental
 *
 * @author Rik Bauwens
 *
 */
public class AccidentalSymbol extends PrimitiveStaffSymbol
{
        public AccidentalSymbol(ValueNode<Double> frameX, ValueNode<Double> staffY,
                                MutableValueNode<Double> staffBase, MutableValueNode<Double> postStaffBase,
                                ValueNode<Double> xNode, MutableValueNode<Double> widthNode,
                                MutableValueNode<Integer> rankNode, ValueNode<Integer> accidentalNode)
        {
                super(frameX, staffY, staffBase, postStaffBase, xNode, widthNode, rankNode);
                init(accidentalNode);
        }

        private void init(ValueNode<Integer> accidentalNode)
        {
                setAccidental(accidentalNode.getValue());
                accidentalNode.addObserver(new Observer()
                {
                        public void onNotify(Object source)
                        {
                                setAccidental(((ValueNode<Integer>) source).getValue());
                        }
                });
        }

        private void setAccidental(int accidentalType)
        {
                if (accidentalType == SymbolConstants.ACCIDENTAL_DOUBLE_FLAT)
                        textGlyph = Fughetta.getGlyph(SymbolConstants.ACC_DOUBLE_FLAT);
                else if(accidentalType == SymbolConstants.ACCIDENTAL_FLAT)
                        textGlyph = Fughetta.getGlyph(SymbolConstants.ACC_FLAT);
                else if(accidentalType == SymbolConstants.ACCIDENTAL_NATURAL)
                        textGlyph = Fughetta.getGlyph(SymbolConstants.ACC_NATURAL);
                else if(accidentalType == SymbolConstants.ACCIDENTAL_SHARP)
                        textGlyph = Fughetta.getGlyph(SymbolConstants.ACC_SHARP);
                else if (accidentalType == SymbolConstants.ACCIDENTAL_DOUBLE_SHARP)
                        textGlyph = Fughetta.getGlyph(SymbolConstants.ACC_DOUBLE_SHARP);
                textGlyph.setSize(SymbolConstants.SYMBOL_SIZE);
                updateNodes();
        }
}
